package com.somsoft.handjc.activity.query.xzsp;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.Utils;
import com.somsoft.handjc.util.XzspDataUtil;

public class XzspQueryBusinessInfoMainActivity extends BaseActivity implements OnItemClickListener{

	private ListView listView; 
	private String ywlsh = "";
    @Override 
    public void onCreate(Bundle savedInstanceState){ 
        super.onCreate(savedInstanceState); 
        MyApplication.getInstance().addActivity(this);
        listView = new ListView(this); 
        Intent it = getIntent();
        ywlsh = it.getStringExtra("ywlsh");
        try {
			listView.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_1,getData(ywlsh)));
		} catch (Exception e) {
			Toast.makeText(XzspQueryBusinessInfoMainActivity.this, "加载数据失败！", Toast.LENGTH_SHORT).show();
		} 
        setContentView(listView); 
        setTitle("已办理业务");
        listView.setOnItemClickListener(this);
        Utils.closeLoading();
    } 

    private List<String> getData(String ywlsh) throws Exception{ 
    	List<String> data = new ArrayList<String>(); 
    	try {
    		List<NameValuePair> params = new ArrayList<NameValuePair>();
    		params.add(new BasicNameValuePair("ywlsh",ywlsh));
            JSONObject obj = XzspDataUtil.detailBase(params);
            String[] ps = obj.getString("overPosition").split("、");
            for(String p : ps){
            	data.add(p);
            }
		} catch (Exception e) {
			throw e;
		}
        return data; 
    }

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		TextView tv = (TextView)arg1;
		String itemValue = tv.getText().toString();
		
		Intent it = new Intent(XzspQueryBusinessInfoMainActivity.this,XzspDetailBusinessInfoActivity.class);
		it.putExtra("itemValue", itemValue);
		it.putExtra("ywlsh", ywlsh);
		
		Utils.openLoading(XzspQueryBusinessInfoMainActivity.this);
		startActivity(it);
	} 
}
